Skip to content

[None][feat] Support DeepSeek-V4 in layer_wise_benchmarks#16774

Open
ruodil wants to merge 2 commits into
NVIDIA:mainfrom
ruodil:user/ruodil/lwb-deepseek-v4-support
Open

[None][feat] Support DeepSeek-V4 in layer_wise_benchmarks#16774
ruodil wants to merge 2 commits into
NVIDIA:mainfrom
ruodil:user/ruodil/lwb-deepseek-v4-support

Conversation

@ruodil

@ruodil ruodil commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

DeepSeek-V4's multi-head hyper-connection (mHC) decoder layers do not fit the generic single-layer harness in tools/layer_wise_benchmarks/runner.py:

  • create_kv_cache_manager: the is_mla branch omitted vocab_size, which DeepseekV4CacheManager.init requires (keyword-only, no default).
  • create_run_pack: V4 layers take the initial residual as hc_state shaped [num_tokens, hc_mult, hidden_size] and their MoE routing needs input_ids; both are now synthesized when the config exposes hc_mult.
  • run_pack(check=True): guarded the NaN/Inf/zero check with isinstance since mHC layers return an HCState, not a Tensor.

Non-V4 models are unaffected (all V4 paths gate on hc_mult / MLA class).

Usage for V4: --moe-backend DEEPGEMM and a --layer-indices slice that starts at layer 0 and covers both compress ratios (e.g. 0,1,2,3).

Dev Engineer Review

  • Added DeepSeek-V4 support in runner.py by:
    • Passing vocab_size to the MLA KV-cache manager.
    • Synthesizing hc_state and input_ids for mHC layers.
    • Restricting NaN/Inf/zero checks to tensor outputs.
    • Gating V4-specific behavior to preserve non-V4 model behavior.
  • V4 benchmarks require --moe-backend DEEPGEMM and layer indices beginning at 0 and covering both compression ratios, e.g. 0,1,2,3.
  • No public API or configuration-file changes were identified.

QA Engineer Review

No test changes.

Description

Test Coverage

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

DeepSeek-V4's multi-head hyper-connection (mHC) decoder layers do not fit the
generic single-layer harness in tools/layer_wise_benchmarks/runner.py:

- create_kv_cache_manager: the is_mla branch omitted vocab_size, which
  DeepseekV4CacheManager.__init__ requires (keyword-only, no default).
- create_run_pack: V4 layers take the initial residual as hc_state shaped
  [num_tokens, hc_mult, hidden_size] and their MoE routing needs input_ids;
  both are now synthesized when the config exposes hc_mult.
- run_pack(check=True): guarded the NaN/Inf/zero check with isinstance since
  mHC layers return an HCState, not a Tensor.

Non-V4 models are unaffected (all V4 paths gate on hc_mult / MLA class).

Usage for V4: --moe-backend DEEPGEMM and a --layer-indices slice that starts at
layer 0 and covers both compress ratios (e.g. 0,1,2,3).

Signed-off-by: Ruodi Lu <ruodil@users.noreply.github.com>
@ruodil
ruodil requested a review from a team as a code owner July 23, 2026 04:20
@ruodil
ruodil requested review from dc3671 and nv-ananjappa July 23, 2026 04:20
@ruodil
ruodil requested review from chenfeiz0326 and hyukn July 23, 2026 04:21
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The layer-wise benchmark runner now prepares DeepSeek-V4 hyper-connection inputs, conditionally validates tensor outputs, and passes vocabulary size when constructing MLA KV-cache managers.

Changes

Benchmark runner behavior

Layer / File(s) Summary
DeepSeek-V4 input preparation
tensorrt_llm/tools/layer_wise_benchmarks/runner.py
Benchmark pack creation reshapes hidden states for configured hc_mult values and adds input_ids for MoE routing.
Validation and MLA cache wiring
tensorrt_llm/tools/layer_wise_benchmarks/runner.py
Output checks now require tensor-valued hidden states, and MLA KV-cache manager construction receives config.vocab_size.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: dc3671

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the PR’s main change and follows the required [None][feat] format.
Description check ✅ Passed The description clearly explains the issue and solution and is mostly complete despite lacking a dedicated test coverage section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tensorrt_llm/tools/layer_wise_benchmarks/runner.py (1)

664-678: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a regression test for the V4 input contract.

Cover hc_mult=4 and a non-V4 configuration, asserting the expanded hidden-state shape and generated input_ids dtype/range. DeepSeek-V4 relies on expanded mHC residual streams and token-ID-based hash routing. (nvidia.github.io)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/tools/layer_wise_benchmarks/runner.py` around lines 664 - 678,
Add a regression test covering the input-preparation logic around the hc_mult
handling, using hc_mult=4 and a non-V4 configuration. Assert that V4 hidden
states expand to [num_tokens, 4, hidden_size], generated input_ids use
torch.int32 and remain within [0, vocab_size), while the non-V4 path preserves
the original hidden-state shape and does not add input_ids.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/tools/layer_wise_benchmarks/runner.py`:
- Around line 664-678: Add a regression test covering the input-preparation
logic around the hc_mult handling, using hc_mult=4 and a non-V4 configuration.
Assert that V4 hidden states expand to [num_tokens, 4, hidden_size], generated
input_ids use torch.int32 and remain within [0, vocab_size), while the non-V4
path preserves the original hidden-state shape and does not add input_ids.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a39b3908-7632-403f-a51a-3f1331349703

📥 Commits

Reviewing files that changed from the base of the PR and between 0a401b4 and 263b526.

📒 Files selected for processing (1)
  • tensorrt_llm/tools/layer_wise_benchmarks/runner.py

@ruodil

ruodil commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61203 [ run ] triggered by Bot. Commit: 263b526 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61203 [ run ] completed with state FAILURE. Commit: 263b526
/LLM/main/L0_MergeRequest_PR pipeline #49447 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@ruodil

ruodil commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot --disable-fail-fast

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". The patterns "*", "*Post-Merge*", and "*PerfSanity*", including equivalent escaped or repeated-star forms and their use in comma-separated lists, require the ci: post-merge approved PR label. Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline. Requires the ci: post-merge approved PR label applied by an active member of NVIDIA/trt-llm-ci-approvers. The approval label remains in place when new commits are pushed.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge". The patterns "*", "*Post-Merge*", and "*PerfSanity*", including equivalent escaped or repeated-star forms and their use in comma-separated lists, require the ci: post-merge approved PR label.

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@ruodil

ruodil commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61514 [ run ] triggered by Bot. Commit: 1795551 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61514 [ run ] completed with state SUCCESS. Commit: 1795551
/LLM/main/L0_MergeRequest_PR pipeline #49730 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants